<?php
namespace Home\Controller;
use Common\Controller\CommonController;


class RuZhuController extends CommonController {

	//店铺入驻首页
	public function index() {

		$list = M('shop') -> where('status=0 or status =2') ->order("ctime desc")-> select();
		$res = array();
		foreach ($list as $key => $value) {
			$value['listimg'] = json_decode($value['listimg']);
			$value['showimg'] = json_decode($value['showimg']);
			$value['yyzz'] = json_decode($value['yyzz']);
			$value['boss_img'] = json_decode($value['boss_img']);
			$res[] = $value;
		}

		$this -> assign('list', $res);
		$this -> display();
	}

	public function show() {
		$id = I('id');
		$shopInfo = M("shop") -> where(array("id" => $id)) -> find();
		if(empty($shopInfo)){
			$this->error('信息不存在');
		}
		$shopInfo['showimg']=explode(',',$shopInfo['showimg']);
		$shopInfo['yyzz']=explode(',',$shopInfo['yyzz']);
		$shopInfo['boss_img']=explode(',',$shopInfo['boss_img']);
		$shopInfo['shop_type'] = $shopInfo['shop_type'] ? M('shop_type')->where(['id'=>$shopInfo['shop_type']])->getField('type_name') : '';
		//P($shopInfo);
		$this -> assign('list', $shopInfo);
		$this -> display();
	}

	


	//通过
	public function allow() {
		$where['id'] = I('id');
		$data = array('status' => 1);
		$res = M('shop') -> where($where) -> save($data);
		if ($res) {
			$this -> ajaxReturn(array('s' => true, 'm' => '申请已通过'));
		} else {
			$this -> ajaxReturn(array('s' => false, 'm' => '操作失败'));
		}
	}

	//拒绝
	public function refuse() {
		$where['id'] = I('id');
		$data = array('status' => 2);
		$res = M('shop') -> where($where) -> save($data);
		if ($res) {
			$this -> ajaxReturn(array('s' => true, 'm' => '申请已拒绝'));
		} else {
			$this -> ajaxReturn(array('s' => false, 'm' => '操作失败'));
		}
	}

	//开启

	public function again() {
		$where['id'] = I('id');
		$data = array('status' => 1);
		$res = M('shop') -> where($where) -> save($data);
		if ($res) {
			$this -> redirect('RuZhu/index');
		}
	}

	//添加店铺
	public function add() {
		$this -> display();
	}

	public function doadd() {
		$uid = I('uid');
		$name = I('name');
		$shopname = I('shopname');
		$ds = I('ds');
		$addr = I('addr');
		$phone = I('phone');
		$card = I('card');
		$listimg = I('listimg');
		$yyzz = I('yyzz');
		$data = array('uid' => $uid, 'name' => $name, 'shopname' => $shopname, 'ds' => $ds, 'addr' => $addr, 'phone' => $phone, 'card' => $card, 'listimg' => $listimg, 'yyzz' => $yyzz, );
		//P($data);
		$shop_list = M('shop') -> data($data) -> save();

		if ($shop_list) {
			$this -> ajaxReturn(array('s' => true, 'm' => '添加成功!'));
		} else {
			$this -> ajaxReturn(array('s' => false, 'm' => "添加失败!"));
		}
	}

}
?>